package fr.ants.controller.command;

import fr.ants.controller.clock.Clock;
import fr.ants.model.Nest;
import fr.ants.view.panel.Canvas;
import fr.ants.view.panel.NestPanel;

/**
 * Command to add a new Nest.
 * 
 * @author Guillaume
 * 
 */
public class NewNestCommand implements Command {

	/**
	 * Canvas.
	 */
	private final Canvas canvas;

	/**
	 * Clock.
	 */
	private final Clock clock;

	/**
	 * Nest panel;
	 */
	private NestPanel nestPanel;

	/**
	 * Build
	 * 
	 * @param canvas
	 *            Canvas.
	 * @param clock
	 *            Clock.
	 */
	public NewNestCommand(final Canvas canvas, final Clock clock) {
		this.canvas = canvas;
		this.clock = clock;
	}

	@Override
	public void execute() {
		if (nestPanel != null) {
			Nest nest = new Nest(clock
					.getSimulator()
					.getGrid()
					.getNode(canvas.getSelectedGridX(),
							canvas.getSelectedGridY()), 4, 250);
			nest.setDelayBetweenSwarms(nestPanel.getDelayBetweenSwarmsValue());
			nest.setMaxNestSize(nestPanel.getMaxNestSizeValue());
			nest.setPheromoneMaxQty(nestPanel.getPheromoneSliderPanelValue());
			nest.setQueenQtyPerSwarm(nestPanel.getQueenQtyPerSwarmValue());
			nest.setInitialAntLifespan(nestPanel
					.getInitialAntLifespanSliderPanelValue());
			clock.getSimulator().getGrid().addNest(nest);
			if (!clock.isRunning()) {
				canvas.repaint();
			}
		}

	}

	/**
	 * We need the nest panel to execute this command.
	 * 
	 * @param nestPanel
	 *            nest panel
	 */
	public void setNestPanel(NestPanel nestPanel) {
		this.nestPanel = nestPanel;
	}

}
